//https://leetcode.cn/problems/valid-triangle-number/description/

class Solution {
public:
    int triangleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int count = 0;
        for (int i = nums.size() - 1; i >= 2; i--) {
            int j = 0, k = i - 1;
            while (j < k) {
                if (nums[j] + nums[k] > nums[i]) {
                    count += (k - j);
                    k--;
                }
                else {
                    j++;
                }
            }
        }
        return count;
    }
};